<template>
  <Modal
    v-model="visible"
    title="测试"
    width="40"
    @on-visible-change="onVisibleChange"
    @on-cancel="handleReset"
  >
    <div>
      <slot name="customForm"></slot>
      <FormCommon ref="commonForm" />
    </div>
    <div class="drawer-footer">
      <Button @click="handleReset">取消</Button>&nbsp;
      <Button type="primary" :loading="modalLoading" @click="ok">提交</Button>
    </div>
  </Modal>
</template>
<script>
import FormCommon from "./FormCommon.vue";
export default {
  name: "",
  components: {
    FormCommon,
  },
  props: {
    modalVisibleProp: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  computed: {
    visible: {
      get: function () {
        return this.modalVisibleProp;
      },
      set: function () {},
    },
  },
  methods: {
    async ok() {
      try {
        let customFormValue = {};
        const customFormInstance = this.$slots.customForm[0].componentInstance;
        if (
          customFormInstance &&
          typeof customFormInstance.getData === "function"
        ) {
          customFormValue = await customFormInstance.getData(); // 自定义表单获取数据
        }
        const commonFormValue = await this.$refs.commonForm.getData(); // 公共表单获取数据
      } catch (error) {
        console.log(error);
      }
    },
    handleReset() {
      this.$emit("update:modalVisibleProp", false);
    },
    onVisibleChange(visible) {
      if (!visible) {
        this.handleReset();
      }
    },
  },
};
</script>
